package org.feifei.order.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.feifei.basic.util.CommonResult;
import org.feifei.basic.util.PageList;
import org.feifei.order.domain.ProductOrder;
import org.feifei.order.query.ProductOrderQuery;
import org.feifei.order.service.ProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author forever
 * @Description: 宠物领养订单生成
 * @date 2021/12/16 16:25
 */
@RestController
@Api(tags = "宠物服务的订单生成接口")
@RequestMapping("/productOrder")
public class ProductOrderController {

    @Autowired
    private ProductOrderService productOrderService;

    /**
     * 用户购买服务提交订单
     * @param params 商品的参数
     *               包括 选择的地址id，商品的id等
     * @param request 用户发起的请求
     * @return
     */
    @PostMapping("/submit")
    public CommonResult submit(@RequestBody Map<String, Object> params, HttpServletRequest request) {
        try {
            String payData = productOrderService.productOrderSubmit(params, request);
            return CommonResult.ok(payData);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failure(e.getMessage());
        }
    }

    /**
     * 获取管理员的领养订单
     * @param productOrderQuery 查询对象
     * @param request 后台发起的请求
     * @return
     */
    @PostMapping("/admin")
    @ApiOperation(value = "管理员领养订单接口",notes = "")
    public PageList<ProductOrder> adminProductOrder(@RequestBody ProductOrderQuery productOrderQuery,
                                                HttpServletRequest request){
        return productOrderService.adminProductOrder(productOrderQuery,request);
    }


    /**
     * 获取用户的领养订单
     * @param productOrderQuery
     * @param request
     * @return
     */
    @PostMapping("/user")
    @ApiOperation(value = "用户领养订单接口",notes = "")
    public PageList<ProductOrder> userProductOrder(@RequestBody ProductOrderQuery productOrderQuery,
                                               HttpServletRequest request){
        return productOrderService.userProductOrder(productOrderQuery,request);
    }
}
